package so.sao.code.service.domain.entity;

import lombok.Data;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.Entity;
import javax.persistence.EntityListeners;

/**
 * 手工登记码段激活信息
 * <p>
 * <p>
 * 主要包含激活方式及激活条件等
 *
 * @author cuijunhua
 */
@Entity
@Data
@EntityListeners(AuditingEntityListener.class)
public class RangeActivation extends BaseEntity {

    /**
     *
     */
    private static final long serialVersionUID = 6190998102194389942L;

    /**
     * 企业ID
     */
    private Long eseId = 0L;
    /**
     * 码段开始序号
     */
    private Long seqnumStart = 0L;
    /**
     * 码段结束序号
     */
    private Long seqnumEnd = 0L;
    /**
     * 品牌ID
     */
    private Long brandId = 0L;
    /**
     * 产品ID
     */
    private Long productId = 0L;
    /**
     * 工厂ID
     */
    private Long factoryId = 0L;
    /**
     * 标签域名，与子域名一起决定标签被存放的nosql库
     */
    private String domain = "";
    /**
     * 标签子域名，进行标签解密时使用
     */
    private String subDomain = "";
    /**
     * 经销商ID
     */
    private Long franchiserId = 0L;
    /**
     * 标签批次ID
     */
    private Long tagBatchId = 0L;

    /**
     * 该批次是否完全激活
     */
    private boolean isAll = false;
    /**
     * 激活方式
     * <p>
     * refer to so.sao.code.enums.ActivationMethod
     */
    private Integer activationMethod = 0;
    /**
     * 激活参数
     * <p>
     * 激活时间点或者激活动作值
     * <p>
     * 供应链上传数据后，从缓存中获取码段及对应的激活参数，通过激活方式及参数的计算，决定是否激活该标签
     */
    //@Convert(converter = TagRangeStatusConvert.class)
    private Integer status = 10;

    private String activationParam = "";

    public RangeActivation() {
    }

    public RangeActivation(Long tagBatchId, Long seqnumStart, Long seqnumEnd, Long eseId,
                           Integer status) {
        super();
        this.tagBatchId = tagBatchId;
        this.seqnumStart = seqnumStart;
        this.seqnumEnd = seqnumEnd;
        this.eseId = eseId;
        this.status = status;
    }


    public String GenUniqueKey() {
        return this.getClass().getSimpleName() + seqnumStart + "p" + productId;
    }
}
